package com.zr.serviceimpl;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.ShowAllUsersDao;
import com.zr.model.Cuser;
import com.zr.service.ShowAllUsersService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service("showAllUsersService")
public class ShowAllUsersServiceImpl implements ShowAllUsersService{

	@Resource
	private  ShowAllUsersDao<Cuser>  showAllUsersDao;

	@Override
	public JSONObject findAllUsers(int page,int rows) {
		JSONObject j = new JSONObject();
		j.put("total", showAllUsersDao.getUsersCount());
		List<Cuser> us = showAllUsersDao.getAllUsers(page, rows);
		JSONArray js = new JSONArray();
		for (Cuser uu : us) {
			JSONObject u = new JSONObject();
			u.put("uid", uu.getUid());
			u.put("uname", uu.getUname());
			u.put("utel", uu.getUtel());
			u.put("ustate", uu.getUstate());
			u.put("rname", uu.getCrole().getRname());
			u.put("disname", showAllUsersDao.getDisnameByDisid(uu.getDisid()));
			js.add(u);
		}
		j.put("rows", js);
		return j;
	}

}
